package com.example.loginregister.business;


import com.example.loginregister.dataaccess.UserDataAccessService;
import com.example.loginregister.entity.User;

public class UserBusinessService {
    private UserDataAccessService userDataAccessService = new UserDataAccessService();

    // 注册用户逻辑
    public boolean registerUser(String username, String password, String email) throws ClassNotFoundException {
        // 先检查用户名是否已存在
        if (userDataAccessService.isUsernameExists(username)) {
            return false;
        }
        // 若不存在，插入新用户信息到数据库
        return userDataAccessService.insertUser(username, password, email);
    }

    // 登录用户逻辑
    public boolean loginUser(String username, String password) throws ClassNotFoundException {
        return userDataAccessService.verifyUserLogin(username, password);
    }

    public boolean loginUser(User user) throws ClassNotFoundException {
        return userDataAccessService.verifyUserLogin(user);
    }
}
